require(['monitor', 'gaodeMap'], function () {

    $('#monitor').monitor({
        canId: '12',
        callback: function (data) {
        	loadData(data) ;
        },
        clearData: function () {
        	loadData({}) ;
        }
    });
    
	$('#iCenter').css({
		width : $(window).width() - 655,
		height : 482
	});
    
	// 高德地图对象
	var bus=null;
	var map = new MapGaoDe(107.49023438,36.24427318, 2);
    
	function loadData(data) {
		if(!$.isEmptyObject(data)){
			//经纬度
			if (data.longitude && data.latitude) {
				if (bus) {
					bus.clear();
				}
				map.setMapLevel(14);
				bus = new Bus(map, '', data.longitude, data.latitude);
				bus.setDirection(data.direction);
				bus.show();
				map.mapMoveTo(data.longitude, data.latitude);
			}
			// 车速
			var chart = $('#speed-chart').highcharts(), point = chart.series[0].points[0];
			var speedVal = data.speedOfAMotorVehicle || 0;
			point.update(speedVal);
			$('#speed-text').text(speedVal);

			// 转速
			var rpmChart = $('#rpm-chart').highcharts(), rmpPoint = rpmChart.series[0].points[0];
			var rpmVal = (data.electricMachineryRotateSpeed || 0) ;
			rmpPoint.update(rpmVal/100);
			$('#rpm-text').text(rpmVal/100);
			// 电机电压
			var bvcChart = $('#djdy-chart').highcharts(), bvcPoint = bvcChart.series[0].points[0];

			var bvcVal = Number((data.electricMachineryControllerBusBarVoltage || 0).toFixed(1));
			if (bvcVal < 0) {
				bvcVal = 0;
			} else if (bvcVal > 400) {
				bvcVal = 400;
			}
			bvcPoint.update(bvcVal);
			$('#djdy-text').text(bvcVal);

			// 电机电流
			var bccChart = $('#djdl-chart').highcharts(), bccPoint = bccChart.series[0].points[0];

			var bccVal = Number((data.electricMachineryControllerBusBarElectricCurrent || 0).toFixed(1));
			bccPoint.update(bccVal);
			$('#djdl-text').text(bccVal);

			var $state = $('#state');
			var electricMachineryControllerStatus=data.electricMachineryControllerStatus||'111';
			if (electricMachineryControllerStatus== "000") {
				$state.text('READY');
			} else if (electricMachineryControllerStatus== "001") {
				$state.text('RUNNING');
			}
			// 档位gearsStatus
			var gear = data.gears;
			if (gear == '0') {
				$('#gear').text('N档');
			} else if (gear == '-1') {
				$('#gear').text('R档');
			} else if (gear == '1') {
				$('#gear').text('D档');
			}else {
				$('#gear').text('-');
			}

			$("#electricMachineryControllerTemperature").html("电机控制器温度(°C):"+(data.electricMachineryControllerTemperature));
			$("#electricMachineryTemperature").html("电机温度(°C)："+(data.electricMachineryTemperature));
			$("#eltMhyCtrlPreEndVtg").html("电机前端电压(v)："+(data.eltMhyCtrlPreEndVtg));
			$("#eltMhyCtrlLastEndVtg").html("电机后端电压(v)："+(data.eltMhyCtrlLastEndVtg));
			$("#electricMachineryControllerBusBarElectricCurrent").html(data.electricMachineryControllerBusBarElectricCurrent);
			$("#inverterTemperature").html((data.inverterTemperature));
			$("#hybridReadyStatus").html("HybridReady状态："+(data.hybridReadyStatus));
			$("#eltMhyOprtTotalTime").html("电机累计工作时间："+(data.electricMachineryRunTime));
		}
	}
	
});